#include "uniCell.hpp"
#include "uniMesh.hpp"
#include "structMeshFunctions.hpp"

namespace hms {


UniCell::UniCell( const UniMesh& mesh, Index x, Index y ) :
	StructCellBase( mesh, x, y )
{}

UniCell::UniCell( const UniMesh& mesh, Index index ) :
	StructCellBase( mesh, index )
{}


auto UniCell::areaImp() const -> scalar {
	/* just rectangles */
#ifdef UNIMESH_PRECALC_CELL_CONSTANTS
	return m_mesh.cells().area();
#else
	return m_mesh.dx() * m_mesh.dy();
#endif
	/* squares for ghost cells */
	//if ( !isGhost(cell) )
	//	return m_mesh.dx() * m_mesh.dy();
	//else
	//	return (cell - nDomainCells() < m_mesh.nCellsX()*2) ?
	//		m_mesh.dx() * m_mesh.dx() :
	//		m_mesh.dy() * m_mesh.dy();
}

auto UniCell::circumfImp() const -> scalar {
#ifdef UNIMESH_PRECALC_CELL_CONSTANTS
	return m_mesh.cells().circumf();
#else
	return 2*(m_mesh.dx() + m_mesh.dy());
#endif
}

auto UniCell::centroidImp() const -> CentroidType {
	assertValidCellIndex(m_mesh,m_i,m_j);
	
#ifdef UNIMESH_PRECALC_CENTROIDS
	return m_mesh.cells().centroids().col(m_index);
#else
	return m_mesh.origin() + Vector2s{
		(m_i + 0.5)*m_mesh.dx(),
		(m_j + 0.5)*m_mesh.dy()
	};
#endif
}

} // end namespace hms
